function isValueEmpty(value) {
  if (typeof value === 'string') {
    value = value.trim();
  }
  // return value === null || value === undefined || value === '';
  return value == null || value === '';
}

//手机&座机号码校验
export const validatePhone = (rule, value, callback) => {
  // let regTel = /^((0\d{2,3}-?\d{7,8})|(1[3465789]\d{9}))$/;
  // let regPhone = /^1[3|4|5|7|8][0-9]\d{8}$/;
  if (typeof value === 'number') {
    value = String(value);
  }
  // *** 如果因为现有的号码不能满足市场需求，电信服务商会增大号码范围。所以一般情况下我们只要验证手机号码为11位，且以1开头 即：^1[0-9]{10}$ ***
  let regTel = /^((0\d{2,3}-?\d{7,8})|(^1[0-9]{10}$))$/;
  if (isValueEmpty(value) || regTel.test(value)) {
    callback();
  } else {
    callback(new Error('电话号码格式不正确'));
  }
}

//身份证号码校验
export const validateIDCard = (rule, value, callback) => {
  let regIDCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  if (isValueEmpty(value) || regIDCard.test(value)) {
    callback();
  } else {
    callback(new Error('身份证号码格式不正确'));
  }
}

//中文校验
export const validateZH = (rule, value, callback) => {
  let regZH = /^[\u4e00-\u9fa5]*$/g;
  if (isValueEmpty(value) || regZH.test(value)) {
    callback();
  } else {
    callback(new Error('请输入中文'));
  }
}

//银行卡号校检
export const validateBCNo  = (rule, value, callback) => {
  let regBCNo = /^([1-9]\d{12,18})$/;
  if (isValueEmpty(value) || regBCNo.test(value)) {
    callback();
  } else {
    callback(new Error('银行卡号格式不正确'));
  }
}


